package com.marklogic.ps.servicetester.domain;

import java.io.IOException;
import java.io.Serializable;
import java.io.StringWriter;

import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class Query implements Serializable {

	private Service service;
	private String name;
	//private org.w3c.dom.Element request;
	//private org.w3c.dom.Document request;
	//private org.jdom.Document jdomDocument;
	private Element requestElement;
	
	private String formattedXml;
	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRequestString() {
		StringWriter sw = new StringWriter();
		
		return sw.toString();
	}
	
	public String getFormattedXml() {
		if (formattedXml == null && requestElement != null) {
			StringWriter xmlString = new StringWriter();
			XMLOutputter XMLoutput = new XMLOutputter();
			try {
				XMLoutput.output(requestElement, xmlString);

			} catch (IOException e) {
			  e.printStackTrace();
			}
			formattedXml = xmlString.toString();
		}
		return formattedXml;
	}

	@Override
	public String toString() {
		return name;
	}

	public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	public Element getRequestElement() {
		return requestElement;
	}

	public void setRequestElement(Element requestElement) {
		this.requestElement = requestElement;
	}
}
